# encoding: utf-8
from __future__ import unicode_literals

from django.contrib.admin.templatetags.admin_list import result_list as admin_list_result_list
from django.contrib.admin.views.main import SEARCH_VAR
from django.template import Library

register = Library()


@register.inclusion_tag('suit3/search_form.html', takes_context=True)
def advanced_search_form(context, cl):
    """
    Displays a search form for searching the list.
    """
    # if cl.result_list.count() > 0:
    #     asf.base_fields['started'].initial = ''
    return {
        'advance_form': context.get('advance_form'),
        'cl': cl,
        'show_result_count': cl.result_count != cl.full_result_count,
        'search_var': SEARCH_VAR
    }


@register.simple_tag
def result_count(cl):
    from django.utils.safestring import mark_safe
    return mark_safe(u'%d 条结果。' % cl.result_count)


def result_list(cl):
    mycl = {'myextracontext': 'something extra'}
    # mycl.update(foo_extra())
    mycl.update(admin_list_result_list(cl))
    return mycl


register.inclusion_tag('my_change_list_results.html')(result_list)
